package org.etl.kfrwe.controller;

import org.etl.kfrwe.bean.FileRepository;
import org.etl.kfrwe.service.FileRepositoryService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class FileRepositoryController {
    @Resource
    private FileRepositoryService fileRepositoryService;

    @RequestMapping("/filerepository/list")
    public List<FileRepository> findAll() {
        return fileRepositoryService.selectList();
    }

    @RequestMapping("/filerepository/jobandtrans_list")
    public List<String> findJobAndTrans(String path) {
        return fileRepositoryService.jobAndTranSelectList(path);
    }

    @RequestMapping("/filerepository/running_trans")
    public String runningTrans(String repositoryName, String directory, String transName, String username, String password) {
        return fileRepositoryService.runningTrans(repositoryName, directory, transName, username, password);
    }

    @RequestMapping("/filerepository/running")
    public String runningJob(String repositoryName, String directory, String name, String username, String password) {
        return fileRepositoryService.running(repositoryName, directory, name, username, password);
    }

    @RequestMapping("/filerepository/viewbox")
    public ModelAndView runningJob(String resourcePath, Model model) {
        model.addAttribute("resourceFile", fileRepositoryService.viewbox(resourcePath));
        ModelAndView mv = new ModelAndView("viewbox");
        return mv;
    }


}
